from pageObjects.HomePage import HomePage
from pageObjects.AddressBookPage import AddressBookPage

import time
import traceback

class AddContactPerson:
    def __init__(self):
        print("add contact person")

    @staticmethod
    def add(driver,contactName,contactEmail,contactPhone,contactComment):
        try:
            homepage = HomePage(driver)
            homepage.addressLink().click()
            time.sleep(3)
            addresspage = AddressBookPage(driver)
            addresspage.createContactPersonButton().click()
            if contactName:
                addresspage.contactPersonName().send_keys(contactName)
                addresspage.contactEmail().send_keys(contactEmail)
            if contactPhone:
                addresspage.contactPhone().send_keys(contactPhone)
            if contactComment:
                addresspage.contactRelation().send_keys(contactComment)
            addresspage.contactSave().click()
        except Exception as e:
            print(e)
if __name__ == '__main__':
    from selenium import webdriver
    import time
    from appModules.LoginAction import LoginAction
    driver = webdriver.Chrome()
    driver.get("http://mail.126.com/")
    time.sleep(5)
    LoginAction.login(driver,"wyu0430","19870303")
    time.sleep(5)
    AddContactPerson.add(driver,"zhangsan","224229@qq.com",'123465',"朋友")
    time.sleep(5)
    assert "zhangsan" in driver.page_source
    driver.quit()
